package Week.D007;

import java.util.HashMap;
import java.util.Map;

public class Solution01 {
    public int calculateTime(String keyboard, String word) {
        Map<Character,Integer> map=new HashMap<>();

        for(int i=0;i<keyboard.length();i++){
            map.put(keyboard.charAt(i),i);
        }

        int curIndex=0;
        int result=0;
        for(int i=0;i<word.length();i++){
            result+=Math.abs(map.get(word.charAt(i))-curIndex);
            curIndex=word.charAt(i);
        }
        return result;
    }
}
